package www.bplead.com.mydemo.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import www.bplead.com.controller.action.student.entity.Student;
import www.bplead.com.controller.action.user.entity.UserInfo;
import www.bplead.com.mydemo.R;

/**
 * Created by wangyangzi on 2016/10/21.
 */
public class StudentInfoAdapter extends BaseAdapter{

    private Context context;
    private List<Student> studentList;

    public StudentInfoAdapter(Context context,List<Student> studentList){
        this.context = context;
        this.studentList = studentList;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    @Override
    public int getCount() {
        return studentList.size();
    }

    @Override
    public Object getItem(int position) {
        return studentList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return studentList.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Student stu = (Student) getItem(position);

        ViewHolder viewHolder = null;

        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.student_item,null);
            viewHolder = new ViewHolder();
            viewHolder.nameTV = (TextView) convertView.findViewById(R.id.student_item_name);
            viewHolder.noTV = (TextView) convertView.findViewById(R.id.student_item_no);
            viewHolder.classTV = (TextView) convertView.findViewById(R.id.student_item_class);
            viewHolder.courseTV = (TextView) convertView.findViewById(R.id.student_item_course);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.nameTV.setText(stu.getName());
        viewHolder.noTV.setText(stu.getNo());
        viewHolder.classTV.setText(stu.get_class().getName());
        if(stu.getCourseList().size() > 0){
            viewHolder.courseTV.setText(stu.getCourseList().get(0).getName());
        }

        return convertView;
    }

    public static class ViewHolder{
        public TextView nameTV;
        public TextView noTV;
        public TextView classTV;
        public TextView courseTV;
    }
}
